Repository navigation
fix(G1): capture/ref inside parallel blocks - named rejection in ruby, rule-local refs in py - #848
Merged
Merged
Conversation
…rallel fails named WO18 G1 (maps parity audit): the tree path rejects captures from a parallel context by design, but the megaregexp fallback crashed with an accidental NoMethodError (undefined method 'max_length') because the deterministic parallel sort calls Sub#max_length on every item class and Item::CaptureGroup/CaptureRef did not define one. Define both (mirroring the rs/ts runtime: a capture's length is its innards' length, a backreference counts 1) so the sort terminates and the intended SystemConversionError surfaces instead: "Can't use CaptureRef in parallel mode". A capture in `from` with a ref-free `to` now runs the megaregexp fallback and produces output. The WO80 spec that pinned the accidental NoMethodError is rewritten to the named rejection; new specs pin max_length and the fallback pass.
WO18 G1 (maps parity audit): parallel_megaregexp wraps every rule in a named group, and the callback handed the template resolver the GLOBAL group list — so a ref(1) template resolved to the wrapper's whole match instead of the rule's first capture (ax -> axX, k3a -> kk3a). parallel_megaregexp now compiles each rule's pattern on its own to get its exact numbered-group count and hands the replacement only the rule-owned slice of the global groups, matching rs interpreter semantics. The docstrings that codified the shifted numbering are corrected; probe vectors from the audit battery pin the canonical outputs (aX / aXB / 3ka).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
WO18 G1 from the maps parity audit (docs/parity/README.md):
capture(...)/ref(N)inside aparallelblock was broken in all engines except rs. This PR fixes the two halves that live here:Item::CaptureGroup/CaptureRefhad nomax_length, so the tree path's deliberate rejection (SystemConversionError) never surfaced — the megaregexp fallback crashed earlier with an accidentalNoMethodError: undefined method 'max_length'insidedeterministic_sort_by_max_length. Both classes now definemax_length(mirroring the rs/ts runtime: a capture's length is its innards', a backreference counts 1), so the sort terminates and the namedSystemConversionError— "Can't use CaptureRef in parallel mode" — surfaces. A capture infromwith a ref-freetonow runs the megaregexp fallback and produces output instead of crashing.parallel_megaregexpwraps each rule in a named group and handed the GLOBAL group list to the replacement callback, soref(1)resolved to the wrapper's whole match instead of the rule's first capture (ax→axX,k3a→kk3a; rs:aX,3ka). Each rule's pattern is now compiled on its own to get its exact numbered-group count, and the replacement receives only the rule-owned slice of the global groups.Semantics per runtime
regex.compile(pattern).groups(the same grammar the alternation embeds). The docstrings that codified the shifted numbering are corrected.tostill executes correctly through the fallback.Test plan (TDD)
TestMegaregexp+TestParallelprobe vectors (ax→aX,axb→aXB,k3a→3ka) — red before (audit values reproduced:axX/axXB/kk3a), green after; full suite unchanged vs a pristineorigin/mainworktree baseline (same single pre-existingtest_api::test_transliterate_known_vectorfailure on both; that suite is skipped in CI —SKIP_PYTHON=1— and is unrelated to G1;INTERSCRIPT_MAPS_IRwith the extracted sha256-verified 3.2.0 artifact does not change it)NoMethodErroris rewritten to the named rejection; new specs pinmax_lengthand the ref-free fallback pass — red before (NoMethodErrorreproduced), green after; fullSKIP_JS=1 SKIP_PYTHON=1 bundle exec rake411 examples, 0 failures, 11 env-gated pending;standardrbcleanto-position captures (literal, offset-immune), so golden rows are unaffected